//
//  NewHomeHeadView.m
//  quxiangtao
//
//  Created by E人一铺 on 2019/2/22.
//  Copyright © 2019年 shanhaijin. All rights reserved.
//

#import "NewHomeHeadView.h"
#import "SearchViewController.h"
#import "TopSearchView.h"
#import "TopBtnView.h"
#import "CycleView.h"

@interface NewHomeHeadView ()

@property (nonatomic,strong) UIImageView *topImage;
@property (nonatomic,strong) TopSearchView *searchView;
@property (nonatomic,strong) TopBtnView *btnView;
@property (strong, nonatomic) CycleView *cycleView;

@property (strong, nonatomic) UILabel *titleName;

@end

@implementation NewHomeHeadView
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.topImage];
        [self addSubview:self.searchView];
        [self addSubview:self.btnView];
        [self addSubview:self.cycleView];
        [self addSubview:self.titleName];
        
    }
    return self;
}

- (void)setParentVc:(UIViewController *)parentVc {
    
    _parentVc = parentVc;
    
    self.btnView.parentVc = parentVc;
    self.cycleView.parentVC = parentVc;
    self.searchView.parentVc = parentVc;
}
- (void) searchBtnClick:(UIGestureRecognizer *)gesture {
    
    NSLog(@"点击搜索");
    
    SearchViewController *searchCtr = [[SearchViewController alloc] init];
    //        searchCtr.categoryType = weakSelf.mainTableViewHeaderView.selectIndex-1;
    searchCtr.categoryType = 1;
    [self.parentVc.navigationController pushViewController:searchCtr animated:NO];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    WS(weakSelf)
    [self.topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mas_top);
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.height.mas_equalTo(jisuan(366));
    }];
    
    [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mas_top).with.offset(40);
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(jisuan(20));
        make.right.mas_equalTo(weakSelf.mas_right).with.offset(jisuan(-20));
        make.height.mas_equalTo(jisuan(68));
    }];
    
    [self.btnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.topImage.mas_bottom).with.offset(-20);
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(jisuan(10));
        make.right.mas_equalTo(weakSelf.mas_right).with.offset(jisuan(-10));
        make.height.mas_equalTo(jisuan(184));
    }];
    
    [self.cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.btnView.mas_bottom).with.offset(10);
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.height.mas_equalTo(jisuan(300));
    }];

    self.cycleView.selectIndexBanner = 0;
    
    [self.titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.cycleView.mas_bottom).with.offset(jisuan(30));
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(jisuan(20));
  
    }];
}

- (CycleView *)cycleView {
    
    if (!_cycleView) {
        _cycleView = [[CycleView alloc] init];
        
    }
    return _cycleView;
}

- (TopBtnView *)btnView {
    
    if (!_btnView) {
        _btnView = [[[NSBundle mainBundle] loadNibNamed:@"TopBtnView" owner:self options:0] lastObject];
    }
    return  _btnView;
}
- (TopSearchView *)searchView {
    
    if (!_searchView) {
        _searchView = [[[NSBundle mainBundle] loadNibNamed:@"TopSearchView" owner:self options:0] lastObject];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchBtnClick:)];
        
        
        [_searchView addGestureRecognizer:tap];
    }
    return  _searchView;
}

- (UIImageView *)topImage {
    if (!_topImage) {
        _topImage = [[UIImageView alloc] init];
        _topImage.image = [UIImage imageNamed:@"APP_Shopping_Header_Icon"];
        
    }
    return _topImage;
}
- (UILabel *)titleName {
    if (!_titleName) {
        _titleName = [[UILabel alloc] init];
        _titleName.text = @"热卖商品";
        _titleName.textColor = [UIColor colorWithHexString:@"1C1C1C"];
        _titleName.font = Font(30);
        
        
    }
    return _titleName;
}

@end
